﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace Ewts.Storage
{
    public partial class WaitInStorageList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User curUser = new User();
                curUser = (User)Session["UserInfo"];
              
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                DataLib.BLL.City bllLib = new DataLib.BLL.City();
            


                // 处理地
                dropGraphics.DataSource = bllLib.GetList("flag1 = '02'");
                dropGraphics.DataTextField = "cityname";
                dropGraphics.DataValueField = "cityname";
                dropGraphics.DataBind();
                dropGraphics.Items.Insert(0, item);

                dropBelong.DataSource = bllLib.GetList("flag1 = '01'");
                dropBelong.DataTextField = "cityname";
                dropBelong.DataValueField = "cityname";
                dropBelong.DataBind();
                dropBelong.Items.Insert(0, item);                
                // dropGraphics.SelectedValue = "";
               
                if (curUser.UserType == "AA")
                {
                    dropGraphics.SelectedValue = curUser.CompanyCity;
                    dropGraphics.Enabled = false;
                }
                else
                {
                    dropGraphics.SelectedItem.Text = "--请选择--";
                }
                //bindData();
            }
        }

        #region 客户端绑定
        /*
        protected void bindData()
        {
            string graphicity = "";
            string belongcity = "";
            if (dropGraphics.SelectedItem.Text != "--请选择--")
                graphicity = dropGraphics.SelectedItem.Text;
            else
                graphicity = "";

            if (dropBelong.SelectedItem.Text != "--请选择--")
                belongcity = dropBelong.SelectedItem.Text;
            else
                belongcity = "";

            DataTable dt = new DataLib.BLL.InStorage().getWaitInStorageList("", graphicity);
            rept.DataSource = dt;
            rept.DataBind();
        }
        */
        #endregion
        protected string GetIDtype(string outtype, string id,string outstatus)
        {
            string str = "";

            if (outstatus == "2")
            {
                str += "移库派车中";
            }
            else if (outstatus == "3")
            {
                str += "移库称重中";
            }
            else
            {

                if (outtype == "6")
                    str += "<a href='InStorage.aspx?cjoid=" + id.ToString() + "'>" + GetHrefOper(outtype) + "</a>";
                else if (outtype == "31")
                {
                    DataLib.BLL.Productions bp = new DataLib.BLL.Productions();
                    DataLib.Model.InStorage m = bp.GetRsidByOutid(int.Parse(id));
                    if(m != null)
                        str += "<a href='/Production/ProduceAudit.aspx?insid=" + m.id.ToString() + "'>" + GetHrefOper(outtype) + "</a>";
                        
                    
                }
                else
                    str += "<a href='InStorage.aspx?outid=" + id.ToString() + "'>" + GetHrefOper(outtype) + "</a>";
            }
            return str;
        }

        protected string GetHrefOper(string outtype)
        {
            string txt = "";
            switch (outtype)
            {
                case "1":
                    txt = "拆解入库";
                    break;
                case "2":
                    txt = "分类入库";
                    break;
                case "31":
                    txt = "生产审核";
                    break;
                case "5":
                    txt = "移库入库";
                    break;
                case "6":
                    txt = "直销入库";
                    break;
                default:
                    break;
            }
            return txt;
        }

        /// <summary>
        /// 获取入库单号
        /// </summary>
        /// <param name="outid">出库单id</param>
        /// <returns></returns>
        public string GetInStorageID(string outid)
        {
            string strinno = "";

            System.Data.DataTable dt = new DataLib.BLL.InStorage().GetList("outid=" + outid).Tables[0];
            if (dt != null && dt.Rows.Count>0)
            {
                strinno = dt.Rows[0]["id"].ToString();
                DataLib.Model.InStorage inmodel = new DataLib.BLL.InStorage().GetModel(int.Parse(strinno));
                strinno = inmodel.wrlno;
            }

             return strinno;
        }

        /// <summary>
        /// 根据虚拟Load号取得Load号总重量
        /// </summary>
        /// <param name="vloadnum"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public string GetLoadWeight(string vloadnum,int flag)
        {
            string weight = new DataLib.BLL.StorageData().GetLoadWeight(vloadnum, flag);
            return weight;
        }

        /// <summary>
        /// 根据虚拟Load获取入库所有日期
        /// </summary>
        /// <param name="vLoadNum">虚拟Load号</param>
        /// <param name="flag">0代表正文显示，其他值代表Title，鼠标移上去的提示</param>
        /// <returns></returns>
        public string GetInStorageDate(string vloadnum, int flag, string outtype, string ins_date)
        {
            if (outtype == "6")
            {
                return ins_date;
            }
            else
            {
                return new DataLib.BLL.StorageData().InStorageDate(vloadnum, flag);
            }
        }

        /// <summary>
        /// 根据出库ID返回当前单号的重量
        /// 
        /// </summary>
        /// <param name="outid"></param>
        /// <param name="flag">0,总重量，1是已入库重量，2是未入库重量</param>
        /// <returns></returns>
        public string GetOutNoWeight(string outid,int flag)
        {
            string strwt = "0";
            decimal waitwt = 0;
            DataLib.Model.OutStorage oModel = new DataLib.BLL.OutStorage().GetModel(int.Parse(outid));
            if (oModel != null)
            {
                if (oModel.totalWeight == null)
                {
                    oModel.totalWeight = 0;
                }
                if (oModel.currentWeight == null)
                {
                    oModel.currentWeight = 0;
                }
                waitwt =(decimal)oModel.totalWeight - (decimal)oModel.currentWeight;
                switch (flag)
                {
                    case 0:
                        strwt = oModel.totalWeight.ToString();
                        break;
                    case 1:
                        strwt = oModel.currentWeight.ToString();
                        break;
                    case 2:
                        strwt = waitwt.ToString();
                        break;
                    default:
                        break;
                }
            }
            return strwt;
        }

        protected void dropGraphics_SelectedIndexChanged(object sender, EventArgs e)
        {
            //bindData();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="flag">标识为1取名称，否则 取编码</param>
        /// <returns></returns>
        public string GetCumByOutID(object id, int flag)
        {
            int outid = int.Parse(id.ToString());
            DataLib.Model.OutStorage model = new DataLib.BLL.OutStorage().GetModel(outid);
            string cumname = "";
            if (model.inDepart == model.belogarea && model.OutDepart != model.graphicCity && model.StorageType != "原料库")
            {
                cumname = model.OutDepart + model.graphicCity + "库";
            }
            else if (model.StorageType != "原料库")
            {
                cumname = model.inDepart + "伟翔";
            }
            else
            {
                DataLib.Model.LoadNum lmodel = new DataLib.BLL.LoadNum().GetLoadID(model.VLoadNum);
                if (lmodel != null)
                {
                    if (flag == 1)
                        cumname = new DataLib.BLL.Cumtomer().GetModel((int)lmodel.customerid).companyname;
                    else
                        cumname = new DataLib.BLL.Cumtomer().GetModel((int)lmodel.customerid).customercode;
                }
            }
            return cumname;
        }

    }
}